package com.wlient.springboot_fileupload.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wlient.springboot_fileupload.entity.UserImage;
import com.wlient.springboot_fileupload.entity.UserImageVO;
import com.wlient.springboot_fileupload.service.UserImageService;
import org.omg.PortableServer.LIFESPAN_POLICY_ID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.engine.IterationStatusVar;

import javax.annotation.Resource;
import java.sql.Wrapper;
import java.util.List;
import java.util.stream.Collectors;

/**
 * (UserImage)表控制层
 *
 * @author makejava
 * @since 2021-08-12 09:57:15
 */
@Controller
@RequestMapping("userImage")
public class UserImageController {

    private String path = "/images/";

    /**
     * 服务对象
     */
    @Autowired
    private UserImageService userImageService;


    @GetMapping("/test")
    public UserImage test() {
        return userImageService.getBaseMapper().selectById(1);
    }


    @GetMapping("/GetImageList")
    public String showbyUserId(@RequestParam(name = "id") String id, Model model) {
        QueryWrapper<UserImage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", id);
        List<UserImage> list = userImageService.getBaseMapper().selectList(queryWrapper);
        List<String> resultList = list.stream().map(m -> m.setImagepath(path + m.getImagepath()).getImagepath()).collect(Collectors.toList());
        model.addAttribute("resultList", resultList);
        return "show";
    }
}
